<?php
class ZeroPayment extends PaymentAPI{
    const API_NAME = 'ZeroPayment';
    private	$_paymentInfo;
    private $_fields;

    public function apiInit(){
        $this->setApiName(self::API_NAME);
        return $this;
    }

    public function apiRequest($request = null){
        $fields = array(
//             'amount' 		=> $this->totalPrice,
            'amount'        => "0.00",
            'invoice_num'	=> $this->getPaymentCode(),
            'description'	=> 'eGunner Penny Auctions',
        );
        $this->_response = '';
        //$this->paymentLog($fields);
        $this->_fields = $fields;
        return $this->_response;
    }

    public function apiResponse($response = null){
        $this->paymentLog($this->_fields);
        return $this->_response;
    }

    public function apiPaymentVaild(){
        return floatval($this->totalPrice) <= 0;
    }

    public function paymentLog($logs,$tpye = 'info'){
        Yii::app()->fileLog
            ->setNamespace('payment')
            ->addDir(date('Y'))
            ->addDir(date('m'))
            ->addDir(date('d'))
            ->addDir($this->getApiName())
            ->addDir($this->getPaymentCode())
            ->setFile($this->getApiName().'_'.$this->getPaymentCode())
            ->addLog($logs,$tpye);
        $model = new PaymentLog();
        $model->type = 3;
        $model->request = $this->getPaymentCode();
        $model->customer_id = Yii::app()->user->id;
        $model->created = time();
        $model->response = json_encode($logs);
        $model->save();
        return $this;
    }
}